<%#
#  Copyright 2009-2010 Michal Trzcinka
#  Licensed under the Apache License, Version 2.0 (the "License");
#  you may not use this file except in compliance with the License.
#  You may obtain a copy of the License at
# 
#  http://www.apache.org/licenses/LICENSE-2.0
# 
#  Unless required by applicable law or agreed to in writing, software distributed
#  under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
#  CONDITIONS OF ANY KIND, either express or implied. See the License for the
#  specific language governing permissions and limitations under the License.
%>

<div class="body_resize">

  <h2><%= t :header, :scope => 'workshops_list' %> <br /> </h2>

  <table cellspacing="0" cellpadding="0" id="box-table-a">
    <thead>
      <tr>
        <th><%=  t :name, :scope => %w{workshops_list table columns} %></th>
        <th></th>
        <th></th>
      </tr>
    </thead>
    <tbody>
      <% @workshops.each do |workshop| %>
        <tr>
          <td><%= h workshop.name %></td>
          <td><%= link_to t(:edit, :scope => %w{workshops_list table rows}), :action => 'edit', :id => workshop.id %></td>
          <td>
            <%= link_to_function t(:delete, :scope => %w{workshops_list table rows}), "confirmDelete('#{url_for(:action => 'destroy', :id => workshop.id)}')" %>
          </td>
        </tr>
      <% end %>
    </tbody>

  </table>

  <%= link_to t(:new_workshop, :scope => %w{workshops_list}), :action => 'new' %>

</div>

<script type="text/javascript">
  var url;
  function handleDelete() {
    var f = document.createElement('form');
    f.style.display = 'none';
    document.body.appendChild(f);
    f.method = 'POST';
    f.action = url;
    var m = document.createElement('input');
    m.setAttribute('type', 'hidden');
    m.setAttribute('name', '_method');
    m.setAttribute('value', 'delete');
    f.appendChild(m);
    f.submit();
  }

  function confirmDelete(url_p) {
    url = url_p;
    confirm('<%= t('workshops_list.confirm_delete') %>', handleDelete);
  }
</script>
